package com.idroc.cdfs.util;

import java.security.MessageDigest;

/**
 * 数据项key工具类
 * @author zhandl(yuyoo4j@163.com)
 * @companay www.idroc.com
 * @2009-8-9 上午01:16:14
 */
public final class KeyUtil {
	
	private static MessageDigest md = null;
	/**
	 * 静态变量初始化
	 */
	static {		
		try {
			md = MessageDigest.getInstance("SHA");
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	/**
	 * 防止非法创建对象
	 *
	 */
	private KeyUtil() {};
	
	public static byte[] toMappingKey(byte[] data) {
		
		 try {
			 md.reset();  
		     return md.digest(data); 
		 } catch (Exception cnse) {
		     throw new RuntimeException("无法创建数据的对应的hash的键.", cnse);
		 }
	}	
}
